package cn.service.impl;

import cn.mapper.HealthAbnormalPersonMapper;
import cn.pojo.HealthAbnormalPerson;
import cn.pojo.dto.OrderAbnormal;
import cn.service.HealthAbnormalPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthAbnormalPersonServiceImpl implements HealthAbnormalPersonService {
    @Autowired
    private HealthAbnormalPersonMapper abnormalPersonMapper;
    @Override
    public Map<String, Object> save(HealthAbnormalPerson healthAbnormalPerson) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = abnormalPersonMapper.saveAbnormal(healthAbnormalPerson) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> update(HealthAbnormalPerson healthAbnormalPerson) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;

        try {
            ok = abnormalPersonMapper.updateAbnormal(healthAbnormalPerson) == 1;
        } catch (Exception e) {
            ok = false;
            e.printStackTrace();
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> delete(Integer orderId) {
        Map<String, Object> res = new HashMap<>();
        boolean ok = false;
        try {
            ok = abnormalPersonMapper.deleteAbnormal(orderId) == 1;
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }

    @Override
    public Map<String, Object> select(String openid, String kind) {
        Map<String, Object> res = new HashMap<>();
        Object ok = false;
        try {
            List<OrderAbnormal> result = abnormalPersonMapper.selectAbnormal(openid, kind);
            if (result.size() > 0) {
                ok = result;
            } else {
                ok = false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            ok = false;
        }
        res.put("msg", ok);
        return res;
    }
}
